package databases

import (
	"github.com/go-xorm/xorm"
	"gitlab.gaodun.com/golib/gderror"
	"time"
	"permission/config"
	"permission/vigo_loger"
)

type Tpo_Sys_User_Navigation_Function struct {
	Id           int64 `xorm:"pk autoincr" json:"-"`
	UserId       int64
	FunctionId   int64
	NavigationId int64
	CreateId     int64     `json:"-"`
	CreateTime   time.Time `xorm:"DateTime created"`
}

type UsersFuncFactory struct {
	Table        Tpo_Sys_User_Navigation_Function
	engine       *xorm.Engine
	RowsSlicePtr []Tpo_Sys_User_Navigation_Function
}

// 返回 user factory
func NewUserFuncFactory() *UsersFuncFactory {
	userFac := UsersFuncFactory{}
	userFac.engine, _ = config.InitEng()
	return &userFac
}

func (uff *UsersFuncFactory) FindInfoByFuncIds(funcIds ...int64) error {
	uff.RowsSlicePtr = []Tpo_Sys_User_Navigation_Function{}
	err := uff.engine.In("FunctionId", funcIds).Distinct("UserId").Find(&(uff.RowsSlicePtr))
	if err != nil {
		vigo_loger.AddGrayLog(gderror.New(err.Error()).Error())
	}

	return err
}
